// $_FILEHEADER_BEGIN ***************************
// 版权声明:Timer
// Copyright © 2015 - Timer All Rights Reserved
// 文件名称: RegiestWXViewController.m
// 创建日期: 15/12/6
// 创 建 人: 甄鑫
// 文件说明: <#content#>
// $_FILEHEADER_END ******************************


#import "RegiestWXViewController.h"
#import "NavHelper.h"
#import "WeChat.h"
#import "LoginModel.h"
#import "LoginViewModel.h"
#import "AlertDialogHelper.h"
#import "MeStatus.h"
#import "VerifyPhoneSceneModel.h"
@interface RegiestWXViewController ()
@property (weak, nonatomic) IBOutlet UIButton *mpWxLoginBtn;
@property (strong, nonatomic) LoginViewModel * loginViewModel;
@property (strong, nonatomic) VerifyPhoneSceneModel * verifySceneModel;
@end

@implementation RegiestWXViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self hideNav];
    _loginViewModel = [LoginViewModel SceneModel];
    _verifySceneModel = [VerifyPhoneSceneModel SceneModel];
    // Do any additional setup after loading the view from its nib.
    @weakify (self);
    [[self.mpWxLoginBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x)
    {
        @strongify (self);
        [self.loginViewModel login:^(id recvData, TYPE_LONGIN type)
         {
             if (TYPE_LONGIN_KEY_SUCCESS != type) {
                 NSString * errorMsg = recvData;
                 [AlertDialogHelper showToast:errorMsg];
                 return ;
             }else{
                 NSString * loginKey = recvData;
                 [[MeStatus sharedInstance] saveLoginKey:loginKey];
                 [self.verifySceneModel sendEnsureVerifyPhoneCb:^(VERIFY_PHONE_STATUS status, id recvData) {
                     if (VERIFY_PHONE_NUM_SUCCESS != status) {
                         NSString * errorMsg = recvData;
                         [AlertDialogHelper showToast:errorMsg];
                         return ;
                     }else{
                         NSString *isVer = recvData;
                         if ([isVer integerValue]==0) {
                             ITLogSP(@"登陆成功,保存loginKey,未验证手机号,前往绑定");
                             [NavHelper gotoVerifyPhoneVC];
                         }else{
                             [[NSNotificationCenter defaultCenter] postNotificationName:NOTI_LoginSuccess object:nil];
                            ITLogSP(@"登陆成功,保存loginKey,已经验证手机号直接返回");
                             [[MeStatus sharedInstance] saveVerifyPhoneKey:@"YES"];
                            [NavHelper gotoFindVC];
                         }
                     }
                 }];
             }
         }];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
